/**
 * Copyright 2014-2020 the original author or authors.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.upb.webserver.common.enums;

import lombok.extern.slf4j.Slf4j;

/**
 * group status in tb_group
 */
@Slf4j
public enum FiscoRemoteGroupStatusEnum {
		/**
		 * running
		 */
		NORMAL(1),
		/**
		 * stopped or removed
		 */
		MAINTAINING(2),
		/**
		 * invalid for different front's group data conflicts with each other, need to remove invalid front
		 */
		CONFLICT_GROUP_GENESIS(3),
		/**
		 * invalid for db's group data conflicts with chain, need to delete data
		 */
		CONFLICT_LOCAL_DATA(4);

		private byte value;

	FiscoRemoteGroupStatusEnum(int groupType) {
			this.value = (byte)groupType;
		}

	public byte getValue() {
		return this.value;
	}

	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder("GroupStatus{");
		sb.append("value=").append(value);
		sb.append('}');
		return sb.toString();
	}



	public static FiscoRemoteGroupStatusEnum getByValue(byte id) {
		for (FiscoRemoteGroupStatusEnum value : FiscoRemoteGroupStatusEnum.values()) {
			if (value.value == id) {
				return value;
			}
		}
		return null;
	}

	public ChainOrAppStatusEnum convertToChainOrAppStatusEnum() {
		switch (this) {
			case NORMAL:
				return ChainOrAppStatusEnum.RUNNING;
			case MAINTAINING:
			case CONFLICT_GROUP_GENESIS:
			case CONFLICT_LOCAL_DATA:
				return ChainOrAppStatusEnum.UN_NORMAL;
		}
		log.error("fail exec method[caseChainOrAppStatusEnum]. not config status:{} ", this.getValue());
		return null;
	}
}

